<?php

namespace App\Http\Middleware;

use Closure;

class AdminPrivilegeCheck
{
    /**
     * 检查后台管理系统的用户是否有对应操作的权限
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = checkUserLoginStatus($request);
        if ($user == false) {
            return redirect('loginFailure');
        } else {
            // 先检查是否是管理员账号
            if ($user['type'] == config('common.adminUser')) {
                return $next($request);
            }
            // 进行权限判断
            // TODO
            return redirect('noPrivilege');
        }
    }
}
